package com.jdbc_;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class Jdbc5 {
    // 方式五：改进方式4，增加配置文件，让连接mysql更加灵活
    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
        // 通过Properties对象，获取配置文件的信息（IO流）
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\com\\jdbc_\\mysql.properties"));
        // 拿值
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");

        Class.forName(driver);  // 建议写上这句话
        Connection connection = DriverManager.getConnection(url, user, password);

        System.out.println("第五种方式获取到的连接：" + connection);
    }
}
